﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using douban.Core.Utils;
using Newtonsoft.Json.Serialization;
using Newtonsoft.Json;

namespace douban.Core.Apis
{
    public class User
    {
        [JsonProperty("name")]
        public string Name { get; set; }

        [JsonProperty("is_suicide")]
        public string IsSuicide { get; set; }

        [JsonProperty("avatar")]
        public string Avatar { get; set; }

        [JsonProperty("uid")]
        public string Uid { get; set; }

        [JsonProperty("alt")]
        public string Alt { get; set; }

        [JsonProperty("type")]
        public string Type { get; set; }

        [JsonProperty("id")]
        public string Id { get; set; }

        [JsonProperty("large_avatar")]
        public string LargeAvatar { get; set; }
    }


    public static partial class Api
    {
        private static readonly string UserUrl = "/v2/group/user/{0}/";

        public static async Task<User> UserGet(string userId)
        {
            var queryData = new[]
            {
                new KeyValuePair<string, string>("fields","rec_topic_count,like_topic_count,topic_count,reply_topic_count,album_count,join_group_count,user,join_groups"), 
            };

            var url = BuildUri(UserUrl, userId);

            var json = await Search(url, queryData);

            return JsonUtil.Deserialize<User>(json);
        }
    }
}
